package com.zm.devmag.back.web;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import java.util.HashMap;

import com.alibaba.fastjson.JSON;
import com.zm.devmag.device.dao.WarehouseMapper;
import com.zm.devmag.device.po.Warehouse;
import com.zm.devmag.device.service.DeviceStatisticsServer;

import org.springframework.ui.Model;
import java.util.Map;


import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.servlet.ModelAndView;
import java.util.List;


@Controller
@RequestMapping("/backstatistics")
public class DeviceStatisticsController {
	
	@Autowired
	private DeviceStatisticsServer dsse;

	@Autowired
	private WarehouseMapper whMapper;
	
	//首页
	@RequestMapping("/first")
	public ModelAndView deviceList(Model model){
		/*Map<String,Object> pxcond= new HashMap<String,Object>();	
		pxcond.put("bhpx", false);
		pxcond.put("tcnypx",true);
		pxcond.put("zjnxpx", false);
		pxcond.put("cgjapx", false);
		model.addAttribute("bhpx", pxcond.get("bhpx"));
		model.addAttribute("tcnypx", pxcond.get("tcnypx"));
		model.addAttribute("zjnxpx", pxcond.get("zjnxpx"));
		model.addAttribute("cgjapx", pxcond.get("cgjapx"));*/
		return new ModelAndView("back/device/devicestatistics");
	}
	
	//查找数据
	@ResponseBody
	@RequestMapping("/findddlist")
	public Object FindDDList(HttpServletRequest request){
		 Map<String, Object> reJson = new HashMap<String, Object>();		 	 
		 Object backdata =dsse.searchDeviceStatistics();
		 reJson.put("backdata", backdata);
        return JSON.toJSONString(reJson);
	}
	//查找数据
	@ResponseBody
	@RequestMapping("/findwidsdd")
	public Object FindWidsDD(@RequestParam(required = false,defaultValue = "1") Long wid,HttpServletRequest request){
		 Map<String, Object> reJson = new HashMap<String, Object>();		 	 
		 Object backdata =dsse.searchStatisticsWidsDD(wid);
		 reJson.put("backdata", backdata);
        return JSON.toJSONString(reJson);
	}
	//设备列表
	@ResponseBody
	@RequestMapping("/dicddetail")
	public Object DicdDetail(long wid,Long dcid,String statu,Integer pageNo,HttpServletRequest request){
		 Map<String, Object> reJson = new HashMap<String, Object>();
		 Map<String, Object>cond= new HashMap<String, Object>();
		 cond.put("dcid", dcid);
		 cond.put("wid", wid);
		 cond.put("status", statu);
		 cond.put("pageNo",(pageNo-1)*20);
		 
		 Object backdata =dsse.searchStatisticsDcidDatail(cond);
		 reJson.put("backdata", backdata);
        return JSON.toJSONString(reJson);
	}
}
